package mya.mes.mdc.module.rest;

import mya.mes.mdc.logic.tag.TagService;
import mya.mes.mdc.logic.tag.impl.TagServiceImpl;
import mya.mes.mdc.model.excel.ExcelData;
import mya.mes.mdc.model.excel.ExcelFileData;
import mya.mes.mdc.model.tag.Shop;
import mya.mes.mdc.module.excel.service.ExcelImportService;
import mya.mes.mdc.module.excel.service.impl.ExcelImportServiceImpl;

import mya.mes.mdc.share.vo.MdcOptions;
import org.apache.commons.lang3.StringUtils;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;

/**
 * tag excel 文件操作
 *
 * @author zll
 */
@Path("/mdc/excel")
public class TagExcelResource {

    @GET
    public String importExcel(@QueryParam("file") String file) {
        if (file != null && StringUtils.isNotBlank(file)) {
            System.out.println("Tag excel file uploaded.Begin parse..." + file);
            ExcelImportService service = new ExcelImportServiceImpl();
            ExcelFileData excel = new ExcelFileData();
            excel.shop = Shop.CUR;
            excel.area = file;
            excel.excelFile = MdcOptions.EXCEL_ROOT_FOLDER + file + ".xlsx";
            ExcelData excelData = service.tagDefExcel(excel);
            if (excelData != null) {
                TagService tagService = new TagServiceImpl();
                tagService.updateTagHolder(excel.shop, excel.area, excelData);
            }
            return "ok";
        }
        return "no";
    }

    @GET
    @Path("/test")
    public String testExcel(@QueryParam("file") String file) {
        return "haha";
    }
}